package com.ruoyi.user.controller;

import java.io.InputStream;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.user.config.AliyunOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.user.domain.UserActor;
import com.ruoyi.user.service.IUserActorService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 演员管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/actor")
public class UserActorController extends BaseController
{
    @Autowired
    private IUserActorService userActorService;

    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;// 阿里云OSS

    /**
     * 查询演员管理列表
     */
    @RequiresPermissions("user:actor:list")
    @GetMapping("/list")
    public TableDataInfo list(UserActor userActor)
    {
        startPage();
        List<UserActor> list = userActorService.selectUserActorList(userActor);
        return getDataTable(list);
    }

    /**
     * 导出演员管理列表
     */
    @RequiresPermissions("user:actor:export")
    @Log(title = "演员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserActor userActor)
    {
        List<UserActor> list = userActorService.selectUserActorList(userActor);
        ExcelUtil<UserActor> util = new ExcelUtil<UserActor>(UserActor.class);
        util.exportExcel(response, list, "演员管理数据");
    }

    /**
     * 获取演员管理详细信息
     */
    @RequiresPermissions("user:actor:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userActorService.selectUserActorById(id));
    }

    /**
     * 新增演员管理
     */
    @RequiresPermissions("user:actor:add")
    @Log(title = "演员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserActor userActor)
    {
        return toAjax(userActorService.insertUserActor(userActor));
    }

    /**
     * 修改演员管理
     */
    @RequiresPermissions("user:actor:edit")
    @Log(title = "演员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserActor userActor)
    {
        return toAjax(userActorService.updateUserActor(userActor));
    }

    /**
     * 删除演员管理
     */
    @RequiresPermissions("user:actor:remove")
    @Log(title = "演员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userActorService.deleteUserActorByIds(ids));
    }

    //图片上传下载
    @RequestMapping("fileUpload")
    public String upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        String s = aliyunOSSUtils.putObject(inputStream, originalFilename);
        return s;
    }
}
